#!/bin/bash

echo "🚀 SmartInput 浏览器扩展快速安装"
echo "=================================="
echo ""

# 检测操作系统和浏览器
if [[ "$OSTYPE" == "darwin"* ]]; then
    # macOS
    echo "🍎 检测到 macOS 系统"
    echo ""
    
    # 检查Chrome是否安装
    if [ -d "/Applications/Google Chrome.app" ]; then
        echo "✅ 检测到 Google Chrome"
        echo "🔗 正在打开 Chrome 扩展管理页面..."
        open -a "Google Chrome" "chrome://extensions/"
        echo ""
        echo "📋 安装步骤："
        echo "1. 在打开的页面右上角启用'开发者模式'"
        echo "2. 点击'加载已解压的扩展程序'"
        echo "3. 选择以下文件夹："
        echo "   $(pwd)/browser-extension"
        echo ""
    else
        echo "❌ 未检测到 Google Chrome"
    fi
    
    # 检查Edge是否安装
    if [ -d "/Applications/Microsoft Edge.app" ]; then
        echo "✅ 检测到 Microsoft Edge"
        echo "🔗 正在打开 Edge 扩展管理页面..."
        open -a "Microsoft Edge" "edge://extensions/"
        echo ""
        echo "📋 安装步骤："
        echo "1. 在打开的页面左侧启用'开发人员模式'"
        echo "2. 点击'加载解压缩的扩展'"
        echo "3. 选择以下文件夹："
        echo "   $(pwd)/browser-extension"
        echo ""
    else
        echo "❌ 未检测到 Microsoft Edge"
    fi
    
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
    # Linux
    echo "🐧 检测到 Linux 系统"
    echo ""
    
    # 尝试打开Chrome
    if command -v google-chrome &> /dev/null; then
        echo "✅ 检测到 Google Chrome"
        echo "🔗 正在打开 Chrome 扩展管理页面..."
        google-chrome "chrome://extensions/" &
        echo ""
        echo "📋 安装步骤："
        echo "1. 在打开的页面右上角启用'开发者模式'"
        echo "2. 点击'加载已解压的扩展程序'"
        echo "3. 选择以下文件夹："
        echo "   $(pwd)/browser-extension"
        echo ""
    else
        echo "❌ 未检测到 Google Chrome"
    fi
    
elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
    # Windows
    echo "🪟 检测到 Windows 系统"
    echo ""
    echo "📋 请手动执行以下步骤："
    echo "1. 打开 Chrome 或 Edge 浏览器"
    echo "2. 访问 chrome://extensions/ 或 edge://extensions/"
    echo "3. 启用开发者模式"
    echo "4. 点击'加载已解压的扩展程序'"
    echo "5. 选择以下文件夹："
    echo "   $(pwd)/browser-extension"
    echo ""
fi

echo "🔧 扩展文件位置："
echo "   $(pwd)/browser-extension"
echo ""
echo "📖 详细安装说明："
echo "   $(pwd)/extension-install-guide.html"
echo ""
echo "🧪 测试页面："
echo "   $(pwd)/test-extension-registration.html"
echo ""
echo "按任意键打开安装指南..."
read -n 1
open extension-install-guide.html 